import { ownHttp } from './ownHttp';
// import { userName } from './comPathName';
//  const userName = localStorage.getItem('username');

/**
 * @use 初始化按钮布局接口
 */
export const initBtnApi = (data) => {
  return ownHttp.post(
    `/api/general/writefile?path=./user/${localStorage.getItem(
      'username'
    )}/layout/layoutConfig.info`,
    data
  );
};
/**
 * @use 获取按钮布局接口
 */

export const getisBtnTopApi = () => {
  return ownHttp.get(`/user/${localStorage.getItem('username')}/layout/layoutConfig.info`);
};

/**
 * @use 新增个人音乐分组
 */
export const addOwnMusicApi = (data) => {
  return ownHttp.post(
    `/api/general/writefile?path=./user/${localStorage.getItem(
      'username'
    )}/groupManager/groupListAll.info`,
    data
  );
};

/**
 * @use 新增个人设备分组
 */
export const addOwnDeviceApi = (data) => {
  return ownHttp.post(
    `/api/general/writefile?path=./user/${localStorage.getItem(
      'username'
    )}/groupManager/deviceGroupListAll.info`,
    data
  );
};

/**
 * @use 获取设备分组信息
 */
export const getOwnDeviceApi = () => {
  return ownHttp.get(
    `/user/${localStorage.getItem('username')}/groupManager/deviceGroupListAll.info`
  );
};

/**
 * @use 修改个人分组名称
 */

export const editOwnMusicNameApi = (data) => {
  return ownHttp.post(`api/general/userfilemanage`, data);
};

// /**
//  * @use 获取个人分组列表
//  */

// export const getGroupListApi = (data) => {
//   return ownHttp.get(
//     `api/general/scanuserdir?path=./user/${userName}/groupManager/groupListAll&username=${userName}&withcontent=1`
//   );
// };

/**
 * @use 获取音乐个人分组列表
 */
export const getGroupListApi = (data) => {
  return ownHttp.get(`/user/${localStorage.getItem('username')}/groupManager/groupListAll.info`);
};

/**
 * @use 获取个人音乐库
 */
export const getOwnMusicListApi = (data) => {
  return ownHttp.get(
    `api/general/scanuserdir?path=./user/${localStorage.getItem('username')}/usermusic/${
      data.groupName
    }/&username=${localStorage.getItem('username')}`
  );
};

/**
 * @use 删除个人音乐库中某个音乐
 */

export const deleteOwnMusicApi = (data) => {
  return ownHttp.post(`api/general/userfilemanage`, data);
};

/**
 * @use 获取上传音乐分组及歌曲信息
 */

export const getUploadGroupApi = () => {
  return ownHttp.get(
    `api/general/scanuserdir?path=./user/${localStorage.getItem(
      'username'
    )}/usermusic/&username=${localStorage.getItem('username')}&withcontent=0
    `
  );
};

/**
 * @use 修改文件夹名称
 */
export const modifyFolderApi = (data) => {
  return ownHttp.post(`api/general/userfilemanage`, data);
};

/**
 * @use 新建文件夹名称
 */
export const addFolderApi = (data) => {
  return ownHttp.post(
    `api/general/writefile?path=./user/${localStorage.getItem('username')}/usermusic/${data.fName}/
    `
  );
};

/**
 * @use 删除文件夹名称
 */
export const deleteFolderApi = (data) => {
  return ownHttp.post(`api/general/userfilemanage`, data);
};

/**
 * @use 新增个人定时任务分组
 */
export const addOwnTimeApi = (data) => {
  return ownHttp.post(
    `/api/general/writefile?path=./user/${localStorage.getItem('username')}/ontimerscheme/${
      data.saveName
    }/timetask.info`,
    data.timeList
  );
};

export const getTimeListApi = (data) => {
  return ownHttp.get(`${data}`);
};

/**
 * @use 修改定时方案名
 */
export const editTimeNameApi = (data) => {
  return ownHttp.post(`api/general/userfilemanage`, data);
};

/**
 * @use 删除某个定时分组
 */

export const deleteTimeNameApi = (data) => {
  return ownHttp.post(`api/general/userfilemanage`, data);
};

/**
 * @use 获取定时器分组列表
 */
export const getOwnTimeApi = () => {
  return ownHttp.get(
    `api/general/scanuserdir?path=./user/${localStorage.getItem(
      'username'
    )}/ontimerscheme&username=${localStorage.getItem('username')}&withcontent=0`
  );
};

/**
 * @use 定时器加入计划接口
 */

export const addTimePlanApi = (data) => {
  return ownHttp.post(
    `/api/general/writefile?path=./user/${localStorage.getItem(
      'username'
    )}/config/runningtimetasktimerscheme.info`,
    data
  );
};

/**
 * @use 获取正在执行定时方案接口
 */
export const getRuningTime = () => {
  return ownHttp.get(
    `/user/${localStorage.getItem('username')}/config/runningtimetasktimerscheme.info`
  );
};

/**
 * @use 播放TTS
 */
export const playTTSApi = (data) => {
  return ownHttp.post(`api/general/playtext`, data);
};

/**
 * @use 添加用户权限
 */

export const addUserApi = (data) => {
  console.log('data', data);
  return ownHttp.post(
    `/api/general/writefile?path=./user/${data.username}/config/permission.info`,
    data.userPermi
  );
};

/**
 * @use 获取用户名
 */
export const getUersNameApi = () => {
  return ownHttp.get(`api/general/scanuserdir?path=./user&username=superadmin&withcontent=0`);
};

/**
 * @use 获取用户列表
 */
export const getUersListApi = () => {
  return ownHttp.get(``);
};

/**
 * @use 删除用户接口
 */

export const delUserApi = (data) => {
  return ownHttp.post(``, data);
};

/**
 * @use 修改用户接口
 */

export const editUserApi = (data) => {
  return ownHttp.post(``, data);
};

/**
 * @use 保存用户的新增分组索引值接口
 */
export const saveUserIndexApi = (data) => {
  return ownHttp.post(
    `/api/general/writefile?path=./user/${localStorage.getItem(
      'username'
    )}/groupManager/controllDevices.info`,
    data
  );
};

/**
 * @use 获取用户的新增分组索引值接口
 */

export const getUserIndexApi = () => {
  return ownHttp.get(`/user/${localStorage.getItem('username')}/groupManager/controllDevices.info`);
};

/**
 * @use 保存地图配置接口(图片，设备经纬度,可显示设备等...)
 */
export const saveMapConfigApi = (data) => {
  return ownHttp.post(
    `/api/general/writefile?path=./user/${localStorage.getItem(
      'username'
    )}/groupManager/mapConfig.info`,
    data
  );
};

/**
 * @use 获取地图配置接口
 */

export const getMapConfigApi = () => {
  return ownHttp.get(`/user/${localStorage.getItem('username')}/groupManager/mapConfig.info`);
};
